package com.woniuxy.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.woniuxy.domain.AlgsMessage;
import com.woniuxy.service.MessageService;
import com.woniuxy.vo.AlgsAnimalExamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniuxy.domain.AlgsAnimalApplication;
import com.woniuxy.service.IAlgsAnimalApplicationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 动物审批Controller
 * 
 * @author ruoyi
 * @date 2023-03-22
 */
@RestController
@RequestMapping("/animalExam")
public class AlgsAnimalApplicationController extends BaseController
{
    @Autowired
    private IAlgsAnimalApplicationService algsAnimalApplicationService;
@Autowired
private MessageService messageService;

    /**
     * 查询动物审批列表
     */
    //@RequiresPermissions("animalExam:animalExam:list")
    @GetMapping("/list")
    public TableDataInfo list(AlgsAnimalApplication algsAnimalApplication)
    {
        startPage();
        List<AlgsAnimalExamVO> list = algsAnimalApplicationService.selectAllAnimalExam();
        return getDataTable(list);
    }

    /**
     * 导出动物审批列表
     */
    //@RequiresPermissions("animalExam:animalExam:export")
    @Log(title = "动物审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsAnimalApplication algsAnimalApplication)
    {
        List<AlgsAnimalApplication> list = algsAnimalApplicationService.selectAlgsAnimalApplicationList(algsAnimalApplication);
        ExcelUtil<AlgsAnimalApplication> util = new ExcelUtil<AlgsAnimalApplication>(AlgsAnimalApplication.class);
        util.exportExcel(response, list, "动物审批数据");
    }

    /**
     * 通过动物审批申请
     */
    //@RequiresPermissions("animalExam:animalExam:query")
    @GetMapping(value = "/{animalApplicationId}")
    public AjaxResult getInfo(@PathVariable("animalApplicationId") Long animalApplicationId)
    {
        AlgsAnimalApplication algsAnimalApplication = algsAnimalApplicationService.selectAlgsAnimalApplicationByAnimalApplicationId(animalApplicationId);
        algsAnimalApplication.setAnimalApplicationBy1(77l);
        int i = algsAnimalApplicationService.updateAlgsAnimalApplication(algsAnimalApplication);
        AlgsMessage algsMessage = new AlgsMessage();
        algsMessage.setMessageMessage("审批通过，请取动物");
        Long teacherId = algsAnimalApplication.getTeacherId();
        algsMessage.setTeacherId(teacherId.intValue());
        algsMessage.setMessageSendDate(new Date());
        algsMessage.setTypeId(80);
        messageService.insertSelective(algsMessage);

        return AjaxResult.success();
    }
    /**
     * 退回动物审批申请
     */
    //@RequiresPermissions("animalExam:animalExam:query")
    @GetMapping(value = "examAnimalback{animalApplicationId}")
    public AjaxResult examAnimalback(@PathVariable("animalApplicationId") Long animalApplicationId)
    {
        AlgsAnimalApplication algsAnimalApplication = algsAnimalApplicationService.selectAlgsAnimalApplicationByAnimalApplicationId(animalApplicationId);
        algsAnimalApplication.setAnimalApplicationBy1(78l);
        int i = algsAnimalApplicationService.updateAlgsAnimalApplication(algsAnimalApplication);
        AlgsMessage algsMessage = new AlgsMessage();
        algsMessage.setMessageMessage("审批不通过，已经退回");
        Long teacherId = algsAnimalApplication.getTeacherId();
        algsMessage.setTeacherId(teacherId.intValue());
        algsMessage.setMessageSendDate(new Date());
        algsMessage.setTypeId(81);
        messageService.insertSelective(algsMessage);
        return AjaxResult.success();
    }
    /**
     * 动物审批申请归档
     */
    //@RequiresPermissions("animalExam:animalExam:query")
    @GetMapping(value = "examAnimalGoDOwn{animalApplicationId}")
    public AjaxResult examAnimalGoDOwn(@PathVariable("animalApplicationId") Long animalApplicationId)
    {
        AlgsAnimalApplication algsAnimalApplication = algsAnimalApplicationService.selectAlgsAnimalApplicationByAnimalApplicationId(animalApplicationId);
        algsAnimalApplication.setAnimalApplicationBy1(79l);
        int i = algsAnimalApplicationService.updateAlgsAnimalApplication(algsAnimalApplication);

        return AjaxResult.success();
    }
    /**
     * 新增动物审批
     */
  //  @RequiresPermissions("animalExam:animalExam:add")
    @Log(title = "动物审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgsAnimalApplication algsAnimalApplication)
    {
        return toAjax(algsAnimalApplicationService.insertAlgsAnimalApplication(algsAnimalApplication));
    }

    /**
     * 修改动物审批
     */
   // @RequiresPermissions("animalExam:animalExam:edit")
    @Log(title = "动物审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgsAnimalApplication algsAnimalApplication)
    {
        return toAjax(algsAnimalApplicationService.updateAlgsAnimalApplication(algsAnimalApplication));
    }

    /**
     * 删除动物审批
     */
  //  @RequiresPermissions("animalExam:animalExam:remove")
    @Log(title = "动物审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{animalApplicationIds}")
    public AjaxResult remove(@PathVariable Long[] animalApplicationIds)
    {
        return toAjax(algsAnimalApplicationService.deleteAlgsAnimalApplicationByAnimalApplicationIds(animalApplicationIds));
    }
}
